package com.czy.owner.adapter;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.czy.owner.R;
import com.czy.owner.entity.SpecialGoodsModel;
import com.czy.owner.entity.UserLocationModel;
import com.czy.owner.utils.glide.GlideUtils;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;


/**
 * Created by wangyang on 2017/5/18 0018.
 */

public class WheelListAdapter extends RecyclerArrayAdapter<SpecialGoodsModel.SpecialGoodsBean> {
    private Context context;

    public WheelListAdapter(Context context) {
        super(context);
        this.context = context;
    }



    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new WheelViewHolder(parent);
    }

    class WheelViewHolder extends BaseViewHolder<SpecialGoodsModel.SpecialGoodsBean> {

        private ImageView itemIvWheel;
        private TextView itemTvName;
        private TextView itemTvPrice;
        private TextView itemTvBottom;
        private RecyclerView itemRvTag;
        private WheelTagAdapter wheelTagAdapter;

        public WheelViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_wheel_list_layout);
            itemIvWheel = $(R.id.item_iv_wheel);
            itemTvName = $(R.id.item_tv_name);
            itemRvTag = $(R.id.item_rv_tag);
            itemTvPrice= $(R.id.item_tv_price);
            itemTvBottom= $(R.id.item_tv_bottom);
            itemRvTag.setLayoutManager(new GridLayoutManager(context, 4));
            wheelTagAdapter = new WheelTagAdapter(context);
            itemRvTag.setAdapter(wheelTagAdapter);
        }

        @Override
        protected int getDataPosition() {
            return super.getDataPosition();
        }

        @Override
        public void setData(final SpecialGoodsModel.SpecialGoodsBean data) {
            super.setData(data);
            wheelTagAdapter.clear();
            wheelTagAdapter.add("");
            wheelTagAdapter.add("");
            wheelTagAdapter.add("");
            wheelTagAdapter.add("");
            GlideUtils.loadImage(context, data.getGoodsLogo(), itemIvWheel, new GlideUtils.ImageLoadListener<String, GlideDrawable>() {
                @Override
                public void onLoadingComplete(String uri, ImageView view, GlideDrawable resource) {

                }

                @Override
                public void onLoadingError(String source, Exception e) {

                }
            }, R.mipmap.default_icon, R.mipmap.default_icon);
            itemTvName.setText(data.getGoodsName());
            itemTvPrice.setText(String.format("%.2f",data.getPrice()));
            itemTvBottom.setText("已售"+data.getSoldCount()+"件 | "+data.getCommentCount()+"评论");
        }
    }

    public interface OnItemSetDefaultListener {
        void onSet(UserLocationModel.ListBean data, int position);
    }


}
